<template>
  <div>
    <el-breadcrumb separator="/" style="margin-bottom: 20px;">
      <el-breadcrumb-item :to="{ path: '/' }">套餐管理</el-breadcrumb-item>
      <el-breadcrumb-item>套餐配置</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-row style="text-align: right; margin-bottom: 24px;">
        <el-button type="primary" @click="addDialog">添加套餐</el-button>
      </el-row>
      <MyPackage :flag="flag"></MyPackage>
    </el-card>

    <!-- 弹框 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="40%" :before-close="handleClose">
      <el-form
        :model="addForm"
        :rules="rules"
        ref="addFormRef"
        label-width="130px"
        class="demo-ruleForm"
      >
        <el-form-item label="套餐类型" prop="models">
          <el-select v-model="addForm.models" placeholder="请选择套餐类型" style="width: 100%;">
            <el-option v-for="(item, index) in CuisineModel" :key="index" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="套餐说明" prop="desc">
          <el-input v-model="addForm.desc"
          :rows="2"
            placeholder="请输入内容"
           type="textarea"
          ></el-input>
        </el-form-item>
        <el-form-item label="开始配送时间" 
        width="100%"
        prop="startTime">
        <el-time-select
        placeholder="起始配送时间"
        v-model="addForm.startTime"
       :picker-options="{
        start: '08:30',
        step: '00:15',
        end: '18:30'
    }">
    </el-time-select>
    </el-form-item>
     <el-form-item label="停止配送时间" prop="endTime">
    <el-time-select
        width="100%"
    placeholder="结束配送时间"
    v-model="addForm.endTime"
    :picker-options="{
      start: '08:30',
      step: '00:15',
      end: '18:30',
      minTime: startTime
    }">
  </el-time-select>
        </el-form-item>
        <el-form-item label="套餐价格" prop="price">
          <el-input v-model="addForm.price"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetClick">取 消</el-button>
        <el-button type="primary" @click="addClick">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from "vuex";
import MyPackage from "@/views/component/package.vue";
export default {
  components: {
    MyPackage
  },
  data() {
    return {
      currentDate: new Date(),
      dialogVisible: false,
      addForm: {},
      flag: false,
      rules: {
        models: [
          { required: true, message: "请选菜品类型", trigger: "change" }
        ],
        desc: [{ required: true, message: "请输入描述", trigger: "blur" }],
        startTime: [{ required: true, message: "请输入开始配送时间", trigger: "blur" }],
        endTime: [{ required: true, message: "请输入停止配送时间", trigger: "blur" }],
        price: [{ required: true, message: "请输入价格", trigger: "blur" }]
      }
    };
  },
  computed: {
    ...mapState(["CuisineModel"])
  },
  methods: {
    addDialog() {
      this.dialogVisible = true;
    },
    handleClose() {
      this.$confirm("确认关闭？")
        .then(_ => {
          this.resetClick();
        })
        .catch(_ => {});
    },
    addClick() {
      this.$api.post(`/api/package/add`, this.addForm).then(res => {
        this.addForm = {};
        this.dialogVisible = false;
        this.flag = !this.flag;
        this.$message.success('添加成功')
      });
    },
    resetClick() {
      this.$refs.addFormRef.resetFields();
      this.dialogVisible = false;
    }
  }
};
</script>

<style scoped>
</style>